(function($) {
    $(function() {
        $('#hexiaoPage').removeClass('dn');
        var lock = false;

        var vm = new Vue({
            el: '#hexiaoPage',
            data: function () {
                return {
                    orderNo: '',
                    error: {
                        show_error: false,
                        msg: ''
                    }
                }
            },
            computed: {
                show_clean: function() {
                    return $.trim(this.orderNo).length > 0 ? true : false
                }
            },
            methods: {
                cleanTelHandler: function(ev) {
                    this.orderNo = ''
                },
                submitHandler: function(shopId) {
                    var _this = this;
                    if (lock) {
                        return false;
                    }                    
                    if ($.trim(this.orderNo.length) == 0) {
                        _this.error = {
                            show_error: true,
                            msg: '请输入订单核销串码'
                        }
                        setTimeout(()=> {
                            _this.error = {
                                show_error: false,
                                msg: ''
                            }  
                        }, 2000)
                        return false;
                    }
                    lock = true;
                    $.mAjax({
                      url: '/order/check-code',
                      data: {
                          cancel_no: _this.orderNo
                      },
                      success: function (res) {
                          if (res.status == 1) {
                            location.href = './order-detail.html?order_no=' + res.data.order_no + '&cancel_no=' + _this.orderNo + '&cancel_num='+res.data.num
                          } else {
                              if (res.error.errorno == '200009') {
                                  layer.open({
                                      content: res.error.errormsg,
                                      btn: ['去上班', '取消'],
                                      yes: function (index) {
                                          location.href = '../my-shop.html?shop_id=' + shopId
                                          layer.close(index);
                                      }
                                  });
                              } else {
                                  _this.error = {
                                      show_error: true,
                                      msg: res.error.errormsg
                                  }
                                  setTimeout(() => {
                                      _this.error = {
                                          show_error: false,
                                          msg: ''
                                      }
                                  }, 2000)
                              }
                          }
                          lock = false;
                      },
                      error: function () {
                          lock = false;
                      }
                  })                    
                }
            }
        });
    })
})(jQuery)

